package com.iknow.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.IKnowApiV4;
import com.iknow.User;
import com.iknow.db.IKnowDataBase;
import com.iknow.file.CacheSystem;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import com.iknow.xmpp.service.aidl.IKnowUser;
import com.iknow.xmpp.service.aidl.IXmppConnection;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.service.aidl.IXmppFacade.Stub;
import java.io.File;

public class UserCenterActivity extends Activity
{
  private static final int REQUEST_IMAGE_CAPTURE = 7;
  private static final int REQUEST_PHOTO_LIBRARY = 8;
  private static final Intent SERVICE_INTENT = new Intent();
  private View.OnClickListener FansButtonClickListener;
  private View.OnClickListener FollowButtonClickListener;
  private View.OnClickListener HeadImageClickListener;
  private View.OnClickListener LoginButtonClickListener;
  private View.OnClickListener MyFavLayoutClickListener;
  private View.OnClickListener MyInfoLayoutClickListener;
  private View.OnClickListener MyMessageLayoutClickListener;
  private View.OnClickListener MyQingboLayoutClickListener;
  private View.OnClickListener MyWordBookLayoutClickListener;
  private View.OnClickListener QinboLayoutClickListener;
  private View.OnClickListener RegisterButtonClickListener;
  private View.OnClickListener SystemConfigLayoutClickListener;
  private final String TAG = "UserCenterActivity";
  private boolean mBinded;
  private RelativeLayout mConfigLayout;
  private Context mContext;
  private String mCurrentSelectPhoto;
  private RelativeLayout mFansLayout;
  private TextView mFansTextView;
  private RelativeLayout mFavLayout;
  private TextView mFavoriteCount;
  private RelativeLayout mFollowLayout;
  private TextView mFollowTextView;
  private ImageView mHeadView;
  private File mImageFile;
  private Uri mImageUri;
  private RelativeLayout mInfoLayout;
  private LinearLayout mLayoutAction;
  private RelativeLayout mLayoutHead;
  private Button mLoginButton;
  private RelativeLayout mMsgLayout;
  private TextView mNameTextView;
  private ProgressDialog mProgressDialog;
  private Button mRegisterButton;
  private Bitmap mSelectBimap;
  private RelativeLayout mShareLayout;
  private FrameLayout mStatus;
  private ServiceConnection mSvrConn;
  private TaskListener mTaskListener;
  private TextView mUnreadMsgTextView;
  private User mUser;
  private UserInfoTask mUserInfoTask;
  private RelativeLayout mWordBookLayout;
  private TextView mWordCount;
  private IXmppFacade mXmppFacade;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
  }

  public UserCenterActivity()
  {
    this.mSvrConn = new XmppServiceConnection(this, null);
    this.mWordCount = null;
    this.mFavoriteCount = null;
    this.QinboLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
      }
    };
    this.LoginButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, LoginActivity.class);
        this.this$0.startActivity(localIntent);
      }
    };
    this.RegisterButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(this.this$0, RegisterActivity.class);
        this.this$0.startActivity(localIntent);
      }
    };
    this.FollowButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), RosterActivity.class);
        localIntent.putExtra("item_type", 1);
        this.this$0.startActivity(localIntent);
      }
    };
    this.FansButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), RosterActivity.class);
        localIntent.putExtra("item_type", 2);
        this.this$0.startActivity(localIntent);
      }
    };
    this.MyInfoLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (UserCenterActivity.access$1(this.this$0) != null)
        {
          Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), UserInfoActivity.class);
          localIntent.putExtra("action_type", "update");
          UserCenterActivity.access$0(this.this$0).startActivity(localIntent);
        }
        while (true)
        {
          return;
          UserCenterActivity.access$2(this.this$0);
        }
      }
    };
    this.MyQingboLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (UserCenterActivity.access$1(this.this$0) != null)
        {
          Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), MyQingboActivity.class);
          UserCenterActivity.access$0(this.this$0).startActivity(localIntent);
        }
        while (true)
        {
          return;
          UserCenterActivity.access$2(this.this$0);
        }
      }
    };
    this.MyFavLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), MyFavoriteActivity.class);
        UserCenterActivity.access$0(this.this$0).startActivity(localIntent);
      }
    };
    this.MyWordBookLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), MyWordBookActivity.class);
        UserCenterActivity.access$0(this.this$0).startActivity(localIntent);
      }
    };
    this.MyMessageLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (UserCenterActivity.access$1(this.this$0) != null)
        {
          Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), MessageActivity.class);
          UserCenterActivity.access$0(this.this$0).startActivity(localIntent);
        }
        while (true)
        {
          return;
          UserCenterActivity.access$2(this.this$0);
        }
      }
    };
    this.SystemConfigLayoutClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Intent localIntent = new Intent(UserCenterActivity.access$0(this.this$0), SystemReferencesActivity.class);
        UserCenterActivity.access$0(this.this$0).startActivity(localIntent);
      }
    };
    this.HeadImageClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        UserCenterActivity.access$3(this.this$0);
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return null;
      }

      public void onCancelled()
      {
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (paramTaskResult != TaskResult.OK)
          Toast.makeText(this.this$0, UserCenterActivity.access$6(this.this$0).getMsg(), 0).show();
        while (true)
        {
          if (UserCenterActivity.access$5(this.this$0) != null)
            UserCenterActivity.access$5(this.this$0).dismiss();
          return;
          Toast.makeText(this.this$0, "修改成功", 0).show();
        }
      }

      public void onPreExecute()
      {
        UserCenterActivity.access$4(this.this$0, new ProgressDialog(this.this$0));
        UserCenterActivity.access$5(this.this$0).setTitle("正在修改头像，请稍等");
        UserCenterActivity.access$5(this.this$0).setCancelable(false);
      }

      public void onProgressUpdate(, Object paramObject)
      {
      }
    };
  }

  private void getFavoriteInfo()
  {
    int i = IKnow.mIKnowDataBase.getWordCount();
    int j = IKnow.mIKnowDataBase.getFavoriteQingBoCount();
    if (i > 0)
    {
      Object[] arrayOfObject2 = new Object[1];
      arrayOfObject2[0] = Integer.valueOf(i);
      String str2 = String.format("%d", arrayOfObject2);
      this.mWordCount.setText(str2);
      this.mWordCount.setVisibility(0);
      if (j <= 0)
        break label112;
      Object[] arrayOfObject1 = new Object[1];
      arrayOfObject1[0] = Integer.valueOf(j);
      String str1 = String.format("%d", arrayOfObject1);
      this.mFavoriteCount.setText(str1);
      this.mFavoriteCount.setVisibility(0);
    }
    while (true)
    {
      while (true)
      {
        return;
        this.mWordCount.setVisibility(8);
      }
      label112: this.mFavoriteCount.setVisibility(8);
    }
  }

  private void initData()
  {
    this.mLayoutHead.setVisibility(0);
    this.mNameTextView.setText(this.mUser.getNick());
    if (!(StringUtil.isEmpty(this.mUser.getImageId())))
    {
      IKnow.mProfileImageCacheManager.displayProfileBimap(this.mHeadView, this.mUser.getImageId());
      int i = IKnow.mIKnowDataBase.getAllUnreadCount();
      if (i <= 0)
        break label151;
      this.mUnreadMsgTextView.setText(String.valueOf(i));
      this.mUnreadMsgTextView.setVisibility(0);
      this.mFollowTextView.setText(String.valueOf(IKnow.mIKnowDataBase.getFollowCount()));
      this.mFansTextView.setText(String.valueOf(IKnow.mIKnowDataBase.getFansCount()));
      if (!(((IKnow)getApplication()).isConnected()))
        break label163;
      this.mStatus.setBackgroundResource(2130837758);
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          return;
          this.mHeadView.setImageResource(2130837551);
        }
        label151: this.mUnreadMsgTextView.setVisibility(8);
      }
      label163: this.mStatus.setBackgroundResource(2130837761);
    }
  }

  private void initView()
  {
    this.mStatus = ((FrameLayout)findViewById(2131296443));
    this.mLayoutHead = ((RelativeLayout)findViewById(2131296442));
    this.mLayoutHead.setVisibility(8);
    this.mLayoutAction = ((LinearLayout)findViewById(2131296560));
    this.mLayoutAction.setVisibility(8);
    this.mLoginButton = ((Button)findViewById(2131296561));
    this.mLoginButton.setOnClickListener(this.LoginButtonClickListener);
    this.mRegisterButton = ((Button)findViewById(2131296562));
    this.mRegisterButton.setOnClickListener(this.RegisterButtonClickListener);
    this.mInfoLayout = ((RelativeLayout)findViewById(2131296568));
    this.mInfoLayout.setOnClickListener(this.MyInfoLayoutClickListener);
    this.mShareLayout = ((RelativeLayout)findViewById(2131296571));
    this.mShareLayout.setOnClickListener(this.MyQingboLayoutClickListener);
    this.mFavLayout = ((RelativeLayout)findViewById(2131296579));
    this.mFavLayout.setOnClickListener(this.MyFavLayoutClickListener);
    this.mWordBookLayout = ((RelativeLayout)findViewById(2131296385));
    this.mWordBookLayout.setOnClickListener(this.MyWordBookLayoutClickListener);
    this.mMsgLayout = ((RelativeLayout)findViewById(2131296576));
    this.mMsgLayout.setOnClickListener(this.MyMessageLayoutClickListener);
    this.mConfigLayout = ((RelativeLayout)findViewById(2131296584));
    this.mConfigLayout.setOnClickListener(this.SystemConfigLayoutClickListener);
    this.mNameTextView = ((TextView)findViewById(2131296437));
    this.mHeadView = ((ImageView)findViewById(2131296338));
    this.mFollowTextView = ((TextView)findViewById(2131296565));
    this.mFollowLayout = ((RelativeLayout)findViewById(2131296564));
    this.mFollowLayout.setOnClickListener(this.FollowButtonClickListener);
    this.mFansTextView = ((TextView)findViewById(2131296567));
    this.mFansLayout = ((RelativeLayout)findViewById(2131296566));
    this.mFansLayout.setOnClickListener(this.FansButtonClickListener);
    this.mWordCount = ((TextView)findViewById(2131296582));
    this.mFavoriteCount = ((TextView)findViewById(2131296580));
    this.mUnreadMsgTextView = ((TextView)findViewById(2131296577));
  }

  private void onImageSelected(Uri paramUri)
  {
    if (paramUri.getScheme().equals("content"))
      this.mImageUri = paramUri;
    while (true)
    {
      ImageManager localImageManager = IKnow.mProfileImageCacheManager.getImageManager();
      String str = IKnow.mCacheSystem.getThumbmailFileName(paramUri.getPath());
      this.mSelectBimap = localImageManager.createThumbnailBitmap(this.mImageUri, 600);
      this.mCurrentSelectPhoto = localImageManager.bitmapToFile(this.mSelectBimap, str).getAbsolutePath();
      this.mHeadView.setImageBitmap(localImageManager.createThumbnailBitmap(this.mImageUri, 200));
      this.mHeadView.setVisibility(0);
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("avatar", this.mCurrentSelectPhoto);
      this.mUserInfoTask = new UserInfoTask(this, null);
      this.mUserInfoTask.setListener(this.mTaskListener);
      UserInfoTask localUserInfoTask = this.mUserInfoTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localUserInfoTask.execute(arrayOfTaskParams);
      return;
      this.mImageUri = Uri.fromFile(new File(paramUri.getPath()));
    }
  }

  private void openImageCaptureMenu()
  {
    try
    {
      this.mImageFile = new File(IKnow.mCacheSystem.createImagefileName());
      this.mImageUri = Uri.fromFile(this.mImageFile);
      Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");
      localIntent.putExtra("output", this.mImageUri);
      startActivityForResult(localIntent, 7);
      return;
    }
    catch (Exception localException)
    {
      Loger.e("UserCenterActivity", localException.getMessage());
    }
  }

  private void openPhotoLibraryMenu()
  {
    Intent localIntent = new Intent("android.intent.action.GET_CONTENT");
    localIntent.setType("image/*");
    localIntent.putExtra("crop", "true");
    startActivityForResult(localIntent, 8);
  }

  private void showImageSelecte()
  {
    CharSequence[] arrayOfCharSequence = new CharSequence[2];
    arrayOfCharSequence[0] = getString(2131361973);
    arrayOfCharSequence[1] = getString(2131361974);
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(getParent());
    localBuilder.setTitle(getString(2131361975));
    localBuilder.setItems(arrayOfCharSequence, new DialogInterface.OnClickListener(this)
    {
      public void onClick(, int paramInt)
      {
        switch (paramInt)
        {
        default:
        case 0:
        case 1:
        }
        while (true)
        {
          while (true)
          {
            return;
            UserCenterActivity.access$9(this.this$0);
          }
          UserCenterActivity.access$10(this.this$0);
        }
      }
    });
    localBuilder.create().show();
  }

  private void startRegisterActivity()
  {
    Intent localIntent = new Intent(this.mContext, LoginActivity.class);
    this.mContext.startActivity(localIntent);
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if ((paramInt1 == 7) && (paramInt2 == -1))
      onImageSelected(this.mImageUri);
    while (true)
    {
      do
        return;
      while ((paramInt1 != 8) || (paramInt2 != -1));
      this.mImageUri = paramIntent.getData();
      if (this.mImageUri == null)
        this.mImageUri = Uri.parse(paramIntent.getAction());
      onImageSelected(this.mImageUri);
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903133);
    this.mContext = this;
    initView();
  }

  protected void onDestroy()
  {
    if ((this.mUserInfoTask != null) && (this.mUserInfoTask.getStatus() == AsyncTask.Status.RUNNING))
      this.mUserInfoTask.cancel(true);
    if (this.mBinded)
      getApplicationContext().unbindService(this.mSvrConn);
    super.onDestroy();
  }

  protected void onPause()
  {
    super.onPause();
  }

  protected void onResume()
  {
    super.onResume();
    getFavoriteInfo();
    this.mUser = IKnow.mIKnowDataBase.getUser();
    if (this.mUser != null)
    {
      this.mLayoutAction.setVisibility(8);
      initData();
      this.mBinded = getApplicationContext().bindService(SERVICE_INTENT, this.mSvrConn, 1);
    }
    while (true)
    {
      return;
      this.mLayoutAction.setVisibility(0);
      this.mLayoutHead.setVisibility(8);
      this.mUnreadMsgTextView.setVisibility(8);
    }
  }

  public boolean onSearchRequested()
  {
    boolean bool;
    if (getParent() instanceof TabActivity)
      bool = getParent().onSearchRequested();
    while (true)
    {
      return bool;
      bool = super.onSearchRequested();
    }
  }

  private class UserInfoTask extends GenericTask
  {
    private String msg = null;

    protected TaskResult _doInBackground()
    {
      TaskResult localTaskResult;
      TaskParams localTaskParams = paramArrayOfTaskParams[0];
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[0] = Integer.valueOf(2131361874);
      publishProgress(arrayOfObject);
      try
      {
        if ((UserCenterActivity.access$7(this.this$0).createConnection() == null) || (!(UserCenterActivity.access$7(this.this$0).createConnection().isAuthentificated())) || (!(UserCenterActivity.access$7(this.this$0).createConnection().authenticatContentUser())))
        {
          this.msg = "网络超时，修改失败";
          localTaskResult = TaskResult.FAILED;
        }
        else
        {
          String str = IKnow.mApi.chageAvatar(localTaskParams.getString("avatar"));
          UserCenterActivity.access$7(this.this$0).createConnection().getIKnowUser().updateUserInfo(str, null, null, null, null);
          IKnow.mIKnowDataBase.updateUserInfo(UserCenterActivity.access$1(this.this$0).getUID(), "image_id", str);
          UserCenterActivity.access$1(this.this$0).setImgeID(str);
          localTaskResult = TaskResult.OK;
        }
      }
      catch (Exception localException)
      {
        this.msg = "网络超时，修改失败";
        Loger.e("UserCenterActivity", localException.getMessage());
        localTaskResult = TaskResult.FAILED;
      }
      return localTaskResult;
    }

    public String getMsg()
    {
      return this.msg;
    }
  }

  private class XmppServiceConnection
  implements ServiceConnection
  {
    public void onServiceConnected(, IBinder paramIBinder)
    {
      UserCenterActivity.access$8(this.this$0, IXmppFacade.Stub.asInterface(paramIBinder));
    }

    public void onServiceDisconnected()
    {
      UserCenterActivity.access$8(this.this$0, null);
    }
  }
}